package com.gf.forcesystem.controller;

import com.gf.forcesystem.model.dto.BaseMessage;
import com.gf.forcesystem.websocket.ForceClientWebsocketManager;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author gaofei
 * @date 2022/6/20 21:54
 * 兵力系统客户端管理
 */
@RestController
@Api(tags = "兵力系统客户端状态查看")
@RequestMapping("forceclient")
public class ForceClientController {
    @Autowired
    private ForceClientWebsocketManager forceClientWebsocketManager;

    @ApiOperation("获取在线的客户端数量")
    @GetMapping("online")
    public Integer online() {
        return forceClientWebsocketManager.getOnlineNumber();
    }

    @ApiOperation("客户端id列表")
    @GetMapping("clientIdList")
    public List<String> clientIdList() {
        return forceClientWebsocketManager.getOnlineClientIdList();
    }

    @ApiOperation("模拟发生消息")
    @PostMapping("simulationMessage")
    public Boolean simulationMessage(@RequestBody BaseMessage baseMessage) {
        forceClientWebsocketManager.broadcastMessage(baseMessage);
        return true;
    }
}
